package com.gk.study.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gk.study.entity.ChatMessage;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
    // MyBatis-Plus会自动处理基础CRUD
    @Select("SELECT DISTINCT CASE " +
            "WHEN sender_id = #{userId} THEN receiver_id " +
            "ELSE sender_id END AS targetId " +
            "FROM chat_message " +
            "WHERE sender_id = #{userId} OR receiver_id = #{userId}")
    List<String> selectTargetIds(@Param("userId") String userId);

}
